package com.wanmait.CarTrading.Util;

public class Pager {
    private int pageNum;//当前页
    private int pageSize;//每页显示条数
    private int dataCount;//总条数



    public int getPageNum() {
        if(pageNum>this.getPageCount()){
            pageNum = this.getPageCount();
        }
        if(pageNum<1)
        {
            pageNum=1;
        }
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        if(pageSize<1)
        {
            pageSize=10;
        }
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getDataCount() {
        return dataCount;
    }

    public void setDataCount(int dataCount) {
        this.dataCount = dataCount;
    }

    //总页数
    public int getPageCount() {
        return  (dataCount-1)/this.getPageSize()+1;
    }
    //上一页
    public int getPrevPageNum()
    {
        if(this.getPageNum()==1) return 1;
        return this.getPageNum()-1;
    }
    //下一页
    public int getNextPageNum()
    {
        if(this.getPageNum()==this.getPageCount()) return this.getPageCount();
        return this.getPageNum()+1;
    }

    //获得导航页码  可以做个属性设置导航页码数量
    public int[] getNavigateNums()
    {
        return null;
    }
    public int getOffset(){
        //分页时从哪页开始
        return (this.getPageNum()-1)*this.getPageSize();
    }
}
